package com.jamila.scancode.controller;

import com.jamila.scancode.entity.User;
import com.jamila.scancode.result.Result;
import com.jamila.scancode.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JAMILA
 * @since 2024-03-31 12:33:18
 */
@Api(tags = "用户控制器")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户手机号码判断是否可以办理预入职，并保存用户手机号信息
     * @param tel
     * @return
     */
    @ApiOperation("判断是否可以办理预入职")
    @GetMapping("preconditions/{tel}")
    public Result preconditions(@PathVariable String tel){
        // TODO: 2024/3/31 根据业务逻辑判断该手机号用户是否可以进行预入职操作
        boolean flag=true;

        User user = new User();
        user.setTel(tel);

        if (flag){
            //允许进行预入职操作
            user.setStatus(0);
        }else {
            //禁止进行预入职操作
            user.setStatus(2);
        }

        userService.saveData(user);
        return flag?Result.ok():Result.fail().message("禁止预入职操作");
    }

    @ApiOperation("更改用户状态")
    @GetMapping("updateStatus/{tel}/{status}")
    public Result updateStatus(@PathVariable String tel,
                               @PathVariable Integer status){
        boolean b=userService.updateStatus(tel,status);
        return b?Result.ok():Result.fail();
    }


}
